// 删除七牛资源图片

let qiniu = require('qiniu');
let {accessKey, bucket, secretKey} = require("../config/qiniuConfig");

// 构建 BucketManager 对象
let mac = new qiniu.auth.digest.Mac(accessKey, secretKey);
let config = new qiniu.conf.Config();
config.zone = qiniu.zone.Zone_z2;
let bucketManager = new qiniu.rs.BucketManager(mac, config);

function delImage(key) {
  return new Promise(((resolve, reject) => {
    bucketManager.delete(bucket, key, function(err, respBody, respInfo) {
      if (err) {
        // console.log(err);
        reject(err);
        //throw err;
      } else {
        // console.log(respInfo.statusCode);
        // console.log(respBody);
        resolve(respInfo.statusCode);
      }
    });
  }))

}

module.exports = delImage;